package com.tanhua.sso.server.controller;

import com.tanhua.result.Result;
import com.tanhua.sso.pojo.Movement;
import com.tanhua.sso.pojo.Visitors;
import com.tanhua.sso.server.service.MovementService;
import com.tanhua.sso.vo.MovementsVo;
import com.tanhua.sso.vo.NearbyUserVo;
import com.tanhua.sso.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("movements")
public class MovementController {

    @Autowired
    private MovementService movementService;

    @PostMapping
    public ResponseEntity movement(Movement movement, MultipartFile [] imageContent,String location) throws IOException {
        log.error("",imageContent+"=================");
        movementService.publish(movement,imageContent,location);
        System.out.println(imageContent);
        return ResponseEntity.status(200).body("发布成功");
    }
    /*查看个人动态*/
    @GetMapping("all")
    public ResponseEntity all(Integer page, Integer pagesize,Long userId ){
        Result result=movementService.all(page,pagesize,userId);
        return ResponseEntity.ok(result);
    }

    /*好友动态*/
    @GetMapping
    public ResponseEntity friendAll(Integer page, Integer pagesize){
        Result result=movementService.friendAll(page,pagesize);
        return ResponseEntity.ok(result);

    }

    /*
    * 推荐动态*/
    @GetMapping("recommend")
    public ResponseEntity recommend(Integer page, Integer pagesize){
        Result result=movementService.recommend(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /*查看个人动态*/
    @GetMapping("/{id}")
    public ResponseEntity getMovementByid(@PathVariable("id") String movementId){
        MovementsVo movementsVo=movementService.getMovementByid(movementId);
        return ResponseEntity.ok(movementsVo);
    }


    /*点赞*/
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable ObjectId id){
        Integer likeCount=movementService.like(id);
        return ResponseEntity.ok(likeCount);
    }

    /*
    * 取消点赞*/
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable ObjectId id){
        Integer count=movementService.disLike(id);
        return ResponseEntity.ok(count);
    }

    /*喜欢*/
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable ObjectId id){
       Integer count= movementService.love(id);
       return ResponseEntity.ok(count);
    }

    /*取消喜欢*/
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable ObjectId id){
        Integer count=movementService.unLove(id);
        return ResponseEntity.ok(count);
    }

    /*谁看过我*/
    @GetMapping("visitors")
    public ResponseEntity visitors(){
        List<TodayBest> nearbyUserVoList=movementService.selectVisitors();
        return ResponseEntity.ok(nearbyUserVoList);
    }
}
